package com.cmb.mybatis.mapper;

import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.Transient;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

public class BaseEntity {

    protected static final DateFormat DATETIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    protected static final DateFormat DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
    
    @Id
    private String id;

    @Column(name = "create_time")
    private Date createTime;

    @Column(name = "last_update_time")
    private Date lastUpdateTime;

    @Transient
    private String createTimeFormat;
    
    public BaseEntity() {
    }

    public BaseEntity(String id, Date createTime, Date lastUpdateTime) {
        super();
        this.id = id;
        this.createTime = createTime;
        this.lastUpdateTime = lastUpdateTime;
    }

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}
    
    public String getCreateTimeFormat() {
        return createTime!=null?DATETIME_FORMAT.format(createTime):"";
    }
    
    @Transient
    public String getCreateDateFormat() {
        return createTime!=null?DATE_FORMAT.format(createTime):"";
    }
}
